/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package junchangmis.codecSetting;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import publicmethod.*;
import java.sql.ResultSet;
import java.util.Vector;

/**
 *
 * @author developers
 */
public class codecMethodNew {

    public static boolean hasCode(String classCode) {
        try {
            DbOperation db = new DbOperation();
            db.DbConnect();
            String sql = "select * from codeNew where code='" + classCode + "'";
            ResultSet rs = db.DBSqlQuery(sql);
            if (rs.next()) {
                return true;
            } else {
                return false;
            }
        } catch (SQLException ex) {
            Logger.getLogger(codecMethodNew.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }

    public static void addCode(String classCode, String meaning) {
        try {
            DbOperation db = new DbOperation();
            db.DbConnect();
            String sql = "insert into codeNew values('" + classCode + "','" + meaning + "')";
            db.DBSqlExe(sql);
            db.DbClose();
        } catch (SQLException ex) {
            Logger.getLogger(codecMethodNew.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void deleteCode(String classCode) {
        try {
            DbOperation db = new DbOperation();
            db.DbConnect();
            String sql = "delete * from codeNew where code='" + classCode + "'";
            db.DBSqlExe(sql);
            db.DbClose();
        } catch (SQLException ex) {
            Logger.getLogger(codecMethodNew.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static String getMeaning(String classCode) {
        try {
            DbOperation db = new DbOperation();
            db.DbConnect();
            String sql = "select meaning from codeNew where code='" + classCode + "'";
            ResultSet rs = db.DBSqlQuery(sql);
            if (rs.next()) {
                return rs.getString(1);
            } else {
                return null;
            }
        } catch (SQLException ex) {
            Logger.getLogger(codecMethodNew.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public static void getAll(Vector<String> code, Vector<String> meaning) {
        try {
            code.clear();
            meaning.clear();
            DbOperation db = new DbOperation();
            db.DbConnect();
            String sql = "select * from codeNew";
            ResultSet rs = db.DBSqlQuery(sql);
            while (rs.next()) {
                code.add(rs.getString(1));
                meaning.add(rs.getString(2));
            }
            db.DbClose();
        } catch (SQLException ex) {
            Logger.getLogger(codecMethodNew.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
